package com.zf.bm.common.core.sys.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;
import com.zf.bm.common.core.base.entity.BaseEntity;
import com.zf.bm.common.core.config.ConfigUtils;
import org.hibernate.validator.constraints.Length;

import java.util.List;

/**
 * 角色Entity
 */
@TableName("sys_role")
public class Role extends BaseEntity<Role> {

    private static final long serialVersionUID = 1L;
    private String name;    // 角色名称
    private String enname;    // 英文名称
    private String roleType;// 权限类型 任务分配：assignment、管理角色：security-role、普通角色：user
    private String dataScope;// 数据范围
    private String useable;        //是否是可用
    @TableField(exist = false)
    private String sysData;        //是否是系统数据对应数据库中is_sys字段
    @TableField(exist = false)
    private User user;        // 根据用户ID查询角色列表
    @TableField(exist = false)
    private List<Menu> menuList = Lists.newArrayList(); // 拥有菜单列表
    /**
     * 是否系统数据,1：系统数据；0：非系统数据
     */
    private String isSys;

//    @IntegrityField
    private String sm3= StringPool.EMPTY;

    public String getSm3() {
        return sm3;
    }
    public void setSm3(String sm3) {
        this.sm3 = sm3;
    }

    // 数据范围（1：所有数据；2：所在公司及以下数据；3：所在公司数据；4：所在部门及以下数据；5：所在部门数据；8：仅本人数据；9：按明细设置）
    public static final String DATA_SCOPE_ALL = "1";
    public static final String DATA_SCOPE_COMPANY_AND_CHILD = "2";
    public static final String DATA_SCOPE_COMPANY = "3";
    public static final String DATA_SCOPE_OFFICE_AND_CHILD = "4";
    public static final String DATA_SCOPE_OFFICE = "5";
    public static final String DATA_SCOPE_SELF = "8";
    public static final String DATA_SCOPE_CUSTOM = "9";

    public String getIsSys() {
        return isSys;
    }

    public void setIsSys(String isSys) {
        this.isSys = isSys;
    }

    public Role() {
        super();
        this.dataScope = DATA_SCOPE_SELF;
        this.useable = ConfigUtils.YES;
    }

    public Role(Long id) {
        super(id);
    }

    public Role(User user) {
        this();
        this.user = user;
    }
    @JsonIgnore
    public String getUseable() {
        return useable;
    }

    public void setUseable(String useable) {
        this.useable = useable;
    }


    @Length(min = 1, max = 100)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Length(min = 1, max = 100)
    public String getEnname() {
        return enname;
    }

    public void setEnname(String enname) {
        this.enname = enname;
    }

    public void setRoleType(String roleType) {
        this.roleType = roleType;
    }

    public String getRoleType() {
        return roleType;
    }

    @JsonIgnore
    public String getDataScope() {
        return dataScope;
    }
    public List<Menu> getMenuList() {
        return menuList;
    }
	public void setMenuIdList(List<Long> menuIdList) {
		menuList = Lists.newArrayList();
		for (Long menuId : menuIdList) {
			Menu menu = new Menu();
			menu.setId(menuId);
			menuList.add(menu);
		}
	}

    public String getSysData() {
        return sysData;
    }

    public void setSysData(String sysData) {
        this.sysData = sysData;
    }

    @JsonIgnore
    public User getUser() {
        return user;
    }
    public void setUser(User user) {
        this.user = user;
    }

}
